package main

import (
	"fmt"
	"math/rand"
	"sort"
	"strconv"
	"sync"
)

func Rands(min, max float64) (convert float64) {
	convert = roundConvert(rand.Float64()*(max-min)+min, 2)
	return
}

func roundConvert(f float64, n int) (res float64) {
	floatStr := fmt.Sprintf("%."+strconv.Itoa(n)+"f", f)
	res, err := strconv.ParseFloat(floatStr, 64)
	if err == nil {
		return
	}
	return
}

func SortPerson(persons Persons) (m sync.Map) {
	//排序
	sort.Sort(persons)
	for ind, person := range persons {
		personInfoMap := List{
			index:    ind,
			name:     person.name,
			fateRate: person.fateRate,
		}
		m.Store(person.name, personInfoMap)
	}
	return
}
